package com.tianji.remark.task;

import com.tianji.remark.constants.RedisConstants;
import com.tianji.remark.service.ILikedRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
@RequiredArgsConstructor
public class LikeTimesCheckTask {

    private static final List<String> LIKES_TYPE = List.of("QA", "NOTE");
    private static final Integer MAX_BIZ_SIZE = 30;
    private final ILikedRecordService likedRecordService;

    //定时任务--每30秒执行一次
//    @Scheduled(fixedDelay = 1000 * 10)
    @Scheduled(cron = "0/10 * * * * ?")
    public void checkLikeTimes() {
        //将redis里面ZSet的点赞数更新到 回答评论表
        for (String s : LIKES_TYPE) {
            likedRecordService.readLikedTimesAndSendMessage(s, MAX_BIZ_SIZE);
        }
    }
}
